//
//  LiuHomePicCell.swift
//  LiuWeiBo
//
//  Created by 刘晓晨 on 2017/3/31.
//  Copyright © 2017年 刘晓晨. All rights reserved.
//

import UIKit

class LiuHomePicCell: UICollectionViewCell {
    
    fileprivate lazy var gifImageView:UIImageView = {
        let imageView = UIImageView(image: UIImage(named: "timeline_image_gif"))
        imageView.isHidden = true
        return imageView
    }()
    
    lazy var picImageView:UIImageView = {
        let imageView = UIImageView(image: UIImage(named: "avatar_default_big"))
        imageView.contentMode = .scaleAspectFill
        imageView.clipsToBounds = true
        return imageView
    }()
    
    var picStr:LiuHomeReweetPicStatuse? {
        didSet {
            if let url = URL(string: (self.picStr?.thumbnail_pic)!) {
                
                if (self.picStr?.thumbnail_pic)!.hasSuffix(".gif") {
                    gifImageView.isHidden = false
                } else {
                    gifImageView.isHidden = true
                }
                
                picImageView.sd_setImage(with: url, placeholderImage: UIImage(named: "avatar_default_big"))
            }
            
        }
        
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate func setupUI() {
        contentView.addSubview(picImageView)
        contentView.addSubview(gifImageView)
        
        //布局
        picImageView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        gifImageView.snp.makeConstraints { (make) in
            make.right.bottom.equalToSuperview()
        }
    }
}
